const {
  getCertificateList
} = require("../../../api/certificate")

// pages/credentials/credentialsList/credentialsList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    certificateList: [],
    pageNo: 1,
    rowCount: 0,
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.pageNo = 1;
    this.data.certificateList.length = 0;
    this.loadCertificateList();
  },

  /**
   * 加载证书列表
   */
  loadCertificateList() {
    getCertificateList(this.data.pageNo).then(res => {
      this.setData({
        certificateList: this.data.certificateList.concat(res.list),
        rowCount: res.rowCount,
      })
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.rowCount > this.data.certificateList.length) {
      this.data.pageNo += 1;
      this.loadCertificateList();
    }
  },

  /**
   * 进入证书详情
   */
  navigatorCertificate(e) {
    const {
      id
    } = e.currentTarget.dataset;
    wx.navigateTo({
      url: '/pages/credentials/detail/detail?id=' + id,
    })
  },
})